package com.blog.service;

import com.blog.domain.Blog;
import com.blog.domain.Type;
import com.blog.domain.User;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./src/blog-security-context.xml",
		"file:./src/blog-service-context.xml",
		"file:./src/blog-dao-context.xml",
		"file:./src/blog-web-context.xml" })
@Transactional
public class TypeServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected TypeService service;

	/**
	 * Instantiates a new TypeServiceTest.
	 *
	 */
	public TypeServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Return all Type entity
	 * 
	 */
	@Test
	public void findAllTypes() {
		// TODO: JUnit - Populate test inputs for operation: findAllTypes 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Type> response = null;
		response = service.findAllTypes(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllTypes
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findTypeByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findTypeByPrimaryKey 
		Integer id = 0;
		Type response = null;
		response = service.findTypeByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findTypeByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Load an existing Type entity
	 * 
	 */
	@Test
	public void loadTypes() {
		Set<Type> response = null;
		response = service.loadTypes();
		// TODO: JUnit - Add assertions to test outputs of operation: loadTypes
	}

	/**
	 * Operation Unit Test
	 * Delete an existing User entity
	 * 
	 */
	@Test
	public void deleteTypeUser() {
		// TODO: JUnit - Populate test inputs for operation: deleteTypeUser 
		Integer type_id = 0;
		Integer related_user_id = 0;
		Type response = null;
		response = service.deleteTypeUser(type_id, related_user_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTypeUser
	}

	/**
	 * Operation Unit Test
	 * Save an existing Type entity
	 * 
	 */
	@Test
	public void saveType() {
		// TODO: JUnit - Populate test inputs for operation: saveType 
		Type type = new com.blog.domain.Type();
		service.saveType(type);
	}

	/**
	 * Operation Unit Test
	 * Save an existing User entity
	 * 
	 */
	@Test
	public void saveTypeUser() {
		// TODO: JUnit - Populate test inputs for operation: saveTypeUser 
		Integer id_1 = 0;
		User related_user = new com.blog.domain.User();
		Type response = null;
		response = service.saveTypeUser(id_1, related_user);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTypeUser
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Type entity
	 * 
	 */
	@Test
	public void countTypes() {
		Integer response = null;
		response = service.countTypes();
		// TODO: JUnit - Add assertions to test outputs of operation: countTypes
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Type entity
	 * 
	 */
	@Test
	public void deleteType() {
		// TODO: JUnit - Populate test inputs for operation: deleteType 
		Type type_1 = new com.blog.domain.Type();
		service.deleteType(type_1);
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Blog entity
	 * 
	 */
	@Test
	public void deleteTypeBlogs() {
		// TODO: JUnit - Populate test inputs for operation: deleteTypeBlogs 
		Integer type_id_1 = 0;
		Integer related_blogs_id = 0;
		Type response = null;
		response = service.deleteTypeBlogs(type_id_1, related_blogs_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTypeBlogs
	}

	/**
	 * Operation Unit Test
	 * Save an existing Blog entity
	 * 
	 */
	@Test
	public void saveTypeBlogs() {
		// TODO: JUnit - Populate test inputs for operation: saveTypeBlogs 
		Integer id_2 = 0;
		Blog related_blogs = new com.blog.domain.Blog();
		Type response = null;
		response = service.saveTypeBlogs(id_2, related_blogs);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTypeBlogs
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
